package scala.test

import scala.io.Source

/**
  * 3、统计每科都及格的学生
  */
object Test05 {
  def main(args: Array[String]): Unit = {
    //读数据
    val scores: List[String] = Source.fromFile("data/score.txt").getLines().toList
    //取数据
    val idAndscore: List[(String, Int)] = scores.map((f:String)=>{
      val split: Array[String] = f.split(",")
      val id: String = split(0)//学生id
      val score: Int = split(2).toInt//学生成绩
      (id,score)
    })
    //以学生id分组
    val group: Map[String, List[(String, Int)]] = idAndscore.groupBy((f:(String,Int))=>f._1)
     val idAndints = group.map((f:(String,List[(String,Int)]))=>{
      val id: String = f._1//学生id
      val values: List[(String, Int)] = f._2//id与成绩的集合
      val scores: List[Int] = values.map((f:(String,Int))=>f._2)//各科成绩集合
       (id,scores)
    })
  }
}
